package com.cloud.xtools.common.response;

import lombok.Getter;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;

/**
 * @author Daixinguo
 */
@Getter
public enum ResponseCode {

    SUCCESS(2000, "Success", HttpStatus.OK),
    CREATED(2000, "Created", HttpStatus.CREATED),
    NO_CONTENT(HttpStatus.NO_CONTENT),
    ERROR(5000, "Error", HttpStatus.INTERNAL_SERVER_ERROR),
    VALIDATED(4000, "参数验证失败", HttpStatus.BAD_REQUEST),
    UNAUTHORIZED(4000,"未登录或者登录状态失效", HttpStatus.UNAUTHORIZED),
    NO_PERMISSION(4000,"您没有当前操作权限", HttpStatus.FORBIDDEN);

    private  int code;
    private String message;
    private final HttpStatus httpStatus;

    ResponseCode(int code, String message, HttpStatus httpStatus) {
        this.code = code;
        this.message = message;
        this.httpStatus = httpStatus;
    }

    ResponseCode(HttpStatus httpStatus) {
        this.httpStatus = httpStatus;
    }

    // 私有构造函数，限制实例化 @AllArgsConstructor 替换
    // private ResponseCode(int code, String message, HttpStatus httpStatusCode) {
    //     this.code = code;
    //     this.message = message;
    //     this.httpStatusCode = httpStatusCode;
    // }
    // @RequiredArgsConstructor  private final HttpStatus httpStatusCode;
    // private ResponseCode(HttpStatus httpStatusCode) {
    //     this.code = code;
    //     this.message = message;
    //     this.httpStatusCode = httpStatusCode;
    // }

    // 自定义业务状态码
    // public static final ResponseCode SUCCESS = new ResponseCode(2000, "Success", HttpStatus.OK);
    // public static final ResponseCode CREATED = new ResponseCode(2000, "Created", HttpStatus.CREATED);
    // public static final ResponseCode NO_CONTENT = new ResponseCode(HttpStatus.NO_CONTENT);
    // public static final ResponseCode ERROR = new ResponseCode(5000, "Error",HttpStatus.OK);
    // // 参数验证未通过
    // public static final ResponseCode VALIDATED = new ResponseCode(4000, "参数验证失败",HttpStatus.BAD_REQUEST);
    //
    // // 提供静态方法动态创建 ResponseCode
    // public static ResponseCode of(int code, String message, HttpStatus httpStatusCode) {
    //     return new ResponseCode(code, message, httpStatusCode);
    // }
}
